package chapter26;

import java.util.concurrent.CompletableFuture;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/2/28 19:15
 */
public class CompletableFutureTest {
    public static void main(String[] args) {
        Supplier<String> taskA = () -> "hello";
        Function<String, String> taskB = t -> t.toUpperCase();
        Consumer<String> taskC = t -> System.out.println("consume:" + t);

        CompletableFuture.supplyAsync(taskA).thenApply(taskB).thenAccept(taskC).join();

        Function<String, CompletableFuture<String>> taskBB = t ->
                CompletableFuture.supplyAsync(() -> t.toUpperCase());

        CompletableFuture.supplyAsync(taskA).thenCompose(taskBB).thenAccept(taskC);

        CompletableFuture<String> taskBBB = CompletableFuture.supplyAsync(() -> "taskB");
        BiFunction<String, String, String> taskCC = (a, b) -> a + "," + b;
        String ret = CompletableFuture.supplyAsync(taskA).thenCombine(taskBBB, taskCC).join();
        System.out.println(ret);
    }
}
